<?php

namespace App\Models\Applet\Sponsor;


class SponsorIntegralRecordsModel extends BaseSponsorModel
{
    protected $table = 'sponsor_integral_records';

    /**
     * 总条数
     * @param int $sponsorId
     * @return int
     */
    public function total(int $sponsorId): int
    {
        return $this->where('sponsor_id', $sponsorId)
                    ->where('deleted', self::DELETED_NO)
                    ->count();
    }

    /**
     * 根据认养记录获取数据
     * @param int $sponsorId
     * @param array $fields
     * @return mixed
     */
    public function getItemsBySponsorId(int $sponsorId, array $fields = self::QUERY_DEFAULT_FIELDS)
    {
        return $this->select($fields)
                    ->where('sponsor_id', $sponsorId)
                    ->where('deleted', self::DELETED_NO)
                    ->orderBy('id', 'desc')
                    ->offset((CURRENT_PAGE - 1) * PAGE_SIZE)
                    ->limit(PAGE_SIZE)
                    ->get()
                    ->toArray();
    }
}
